package com.fldx.baseboot.web.demo;

import com.fldx.baseboot.common.core.controller.BaseController;
import com.fldx.baseboot.common.core.domain.AjaxResult;
import com.fldx.baseboot.web.demo.service.DemoService;
import com.fldx.baseboot.web.domain.DemoEn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 示例控制器
 * @author 范书铭
 */
@Api("示例")
@RestController
@RequestMapping("/demo/config")
public class DemoController extends BaseController {
    @Resource
    private DemoService demoService;

    /**
     * 示例方法：列表
     * @param config
     * @return
     */
    @ApiOperation("示例方法:列表")
    @PreAuthorize("@ss.hasPermi('test:demo:list')")
    @GetMapping("/list")
    public AjaxResult list(DemoEn config) {
        startPage();
        List<DemoEn> list = demoService.selectDemoEn(config);
        return success(list);
    }

    /**
     * 示例方法：查询详情
     * @param id
     * @return
     */
    @ApiOperation("示例方法:查询详情")
    @PreAuthorize("@ss.hasPermi('test:demo:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable(value = "id") Long id) {
        Object info = demoService.getInfo(id);
        return success(info);
    }


    @ApiOperation("新增示例")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody DemoEn demoEn) {
        demoService.create(demoEn);
        return success();
    }


    @ApiOperation("更新用户")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody DemoEn demoEn) {
        return success(demoService.update(demoEn));
    }


    @ApiOperation("删除示例信息")
    @ApiImplicitParam(name = "userId", value = "示例ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{userId}")
    public AjaxResult delete(@PathVariable Long userId) {
        demoService.delete(userId);
        return success();
    }
}
